language: c

compiler:
  - gcc
  - clang

env:
  - CFLAGS="-W -Wall"
  - CFLAGS="-W -Wall -O2" LDFLAGS="--static"
  - CFLAGS="-W -Wall -O2" CONFIGURE_FLAGS="--without-iconv"
  - CFLAGS="-W -Wall -O2 -g -fwrapv -fsanitize=address"
  - CFLAGS="-m32 -W -Wall"
  - CFLAGS="-m32 -W -Wall -O2" LDFLAGS="--static"
  - CFLAGS="-m32 -W -Wall -O2" CONFIGURE_FLAGS="--without-iconv"
  - CFLAGS="-m32 -W -Wall -O2 -g -fwrapv -fsanitize=address"

addons:
  apt:
    packages:
      - libc6-dev-i386
      - gcc-multilib

matrix:
  exclude:
    - compiler: clang
      env: CFLAGS="-m32 -W -Wall -O2 -g -fwrapv -fsanitize=address"
  include:
    - compiler: gcc
      dist: bionic
      env: CFLAGS="-W -Wall -O2 -g"
    - compiler: clang
      dist: bionic
      env: CFLAGS="-W -Wall -O2 -g"
    - compiler: gcc
      dist: focal
      env: CFLAGS="-W -Wall -O2 -g"
    - compiler: clang
      dist: focal
      env: CFLAGS="-W -Wall -O2 -g"
    - compiler: gcc
      env: CFLAGS="-mx32 -W -Wall -O2 -g -fwrapv" LDFLAGS="--static"
      addons:
        apt:
          packages:
            - libc6-dev-x32
            - gcc-multilib
    - compiler: powerpc-linux-gnu-gcc
      env: CFLAGS="-W -Wall -O2 -g -fwrapv" LDFLAGS="--static" CONFIGURE_FLAGS="--host=powerpc-linux-gnu" RUN="qemu-ppc"
      addons:
        apt:
          packages:
            - gcc-powerpc-linux-gnu
            - libc6-dev-powerpc-cross
            - qemu-user
    - compiler: powerpc-linux-gnu-gcc
      env: CFLAGS="-W -Wall -O2 -g -fwrapv" CONFIGURE_FLAGS="--host=powerpc-linux-gnu" RUN="qemu-ppc /usr/powerpc-linux-gnu/lib/ld.so.1 --library-path /usr/powerpc-linux-gnu/lib"
      addons:
        apt:
          packages:
            - gcc-powerpc-linux-gnu
            - libc6-dev-powerpc-cross
            - libc6-powerpc-cross
            - qemu-user
      before_script:
        - VERSION=`dpkg-query -W -f='${Version}\n' libc6-powerpc-cross | head -1 | sed 's/\(ubuntu[0-9]*\).*/\1/'`
        - SOURCE=`dpkg-query -W -f='${Source}\n' libc6 | head -1`
        - PREFIX=`echo "$SOURCE" | sed 's/^\(.\).*/\1/'`
        - wget "http://ports.ubuntu.com/pool/main/$PREFIX/$SOURCE/libc6_${VERSION}_powerpc.deb" -O /tmp/libc6_powerpc.deb
        - dpkg -x /tmp/libc6_powerpc.deb /tmp/libc6_powerpc
        - export GCONV_PATH=/tmp/libc6_powerpc/usr/lib/powerpc-linux-gnu/gconv
    - compiler: arm-linux-gnueabi-gcc
      env: CFLAGS="-W -Wall -O2 -g -fwrapv" LDFLAGS="--static" CONFIGURE_FLAGS="--host=arm-linux-gnueabi" RUN="qemu-arm"
      addons:
        apt:
          packages:
            - gcc-arm-linux-gnueabi
            - libc6-dev-armel-cross
            - qemu-user
    - compiler: arm-linux-gnueabi-gcc
      env: CFLAGS="-W -Wall -O2 -g -fwrapv" CONFIGURE_FLAGS="--host=arm-linux-gnueabi" RUN="qemu-arm /usr/arm-linux-gnueabi/lib/ld-linux.so.3 --library-path /usr/arm-linux-gnueabi/lib"
      addons:
        apt:
          packages:
            - gcc-arm-linux-gnueabi
            - libc6-dev-armel-cross
            - libc6-armel-cross
            - qemu-user
      before_script:
        - VERSION=`dpkg-query -W -f='${Version}\n' libc6-armel-cross | head -1 | sed 's/\(ubuntu[0-9]*\).*/\1/'`
        - SOURCE=`dpkg-query -W -f='${Source}\n' libc6 | head -1`
        - PREFIX=`echo "$SOURCE" | sed 's/^\(.\).*/\1/'`
        - wget "http://ports.ubuntu.com/pool/main/$PREFIX/$SOURCE/libc6-armel_${VERSION}_armhf.deb" -O /tmp/libc6-armel_armhf.deb
        - dpkg -x /tmp/libc6-armel_armhf.deb /tmp/libc6-armel_armhf
        - export GCONV_PATH=/tmp/libc6-armel_armhf/usr/lib/arm-linux-gnueabi/gconv

script:
  - if test "$LDFLAGS" != "--static"; then export CHECK_ERRORS=1; fi
  - ./autogen.sh
  - ./configure $CONFIGURE_FLAGS
  - make
  - make check

after_failure:
  - cat config.log
  - cat tests/test-suite.log
